package presentation.controller;

import javax.persistence.*;

/**
 *
 * @author zergio
 */
public class ControlSplash {

    public boolean isDatabaseUp() {
        EntityManagerFactory emf = null;
        EntityManager em = null;
        boolean flag;
        try {
            emf = Persistence.createEntityManagerFactory("StunnicusPU");
            em = emf.createEntityManager();
            EntityTransaction tx = null;
            flag = test(em);
        } catch (Exception e) {
            e.printStackTrace();
            flag = false;
        } finally {
            if (em != null) {
                em.clear();
                em.close();
            }
        }
        return flag;
    }

    public boolean test(EntityManager em) {

        Query q = em.createQuery("SELECT u FROM Student u");
        
        try {
            q.getFirstResult();
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
